class Setup < ActiveRecord::Migration
  def up
    create_table :provinces do |t|
      t.integer :code, :null => false
      t.string :name, :null => false
      t.timestamps
    end

    create_table :cities do |t|
      t.integer :code, :null => false
      t.string :name, :null => false
      t.integer :province_code, :null => false
      t.timestamps
    end

    add_index :cities, :province_code
    
    create_table :zones do |t|
      t.integer :code, :null => false
      t.string :name, :null => false
      t.integer :city_code, :null => false
      t.integer :province_code, :null => false
      t.timestamps
    end

    add_index :zones, :province_code
    add_index :zones, :city_code

    create_table "current_clients", :force => true do |t|
      t.string   "vip"
      t.string   "client_type", :null => false, :default => 'CE'
      t.integer  "access_point_id"
      t.integer  "state", :default => 0
      t.string  "ip"
      t.string  "username"
      t.string  "password"
      t.datetime "heartbeat_at"
      t.timestamps
    end
    add_index :current_clients, :client_type
    add_index :current_clients, :access_point_id


    create_table "access_points", :force => true do |t|
      t.string   "mac"
      t.integer  "deliver_id"
      t.integer  "ipqam_id"
      t.integer  "channel_id"
      t.string  "deliver_ip"
      t.string  "ipqam_ip"
      t.integer  "channel_port", :default => 0
      t.datetime "heartbeat_at"
      t.timestamps
    end
    add_index :access_points, :deliver_id
    add_index :access_points, :ipqam_id
    add_index :access_points, :channel_id
    
    create_table "clients", :force => true do |t|
      t.string  "mac", :null => false
      t.boolean "is_online", :default => false
      t.string  "kind", :limit => 20, :default => "CE", :null => false
      t.boolean "available", :defalut => false
      t.datetime "activate_at"
      t.integer "state"
      t.integer "frequence"
      t.string "client_type"
      t.string "ipqam_ip", :limit => 30
      t.string "deliver_ip", :limit => 30
      t.string "mac"
      t.string "ip", :limit => 30
      t.string "vip", :limit => 30
      t.datetime "login_at"
      t.datetime "logout_at"
      t.timestamps
    end
    add_index :clients, :kind

    create_table "css_exceptions", :force => true do |t|
      t.integer  "code"
      t.string   "title"
      t.text "content"
      t.string  "ip"
      t.string "mac"
      t.string   "client_type"
      t.timestamps
    end
    add_index "css_exceptions", :client_type

    create_table "ipqams", :force => true do |t|
      t.integer "deliver_id"
      t.integer "pid"
      t.string "deliver_ip"
      t.boolean "available", :defalut => false
      t.integer "city_code"
      t.integer "zone_code"
      t.integer "province_code"
      t.string  "room"
      t.string  "ip", :null => false, :limit => 30
      t.timestamps
    end
    
    add_index "ipqams", :province_code
    add_index "ipqams", :city_code
    add_index "ipqams", :zone_code


    create_table "channels", :force => true do |t|
      t.integer "port"
      t.integer "frequence"
      t.string "deliver_ip"
      t.boolean "available", :defalut => false
      t.integer "ipqam_id"
      t.string "ipqam_ip"
      t.timestamps
    end

    create_table "users", :force => true do |t|
      t.string   "nickname"
      t.integer  "province_code"
      t.integer  "city_code"
      t.string   "username"
      t.string   "home_page"
      t.string   "avatar"
    end

    create_table "licenses", :force => true do |t|
      t.string   "code"
      t.string   "ip"
      t.string   "ipqam_ip"
      t.integer  "ipqam_port"
      t.integer  "frequence"
      t.integer  "city_code"
      t.string   "belongs_area"
      t.datetime "authorization_time"
      t.datetime "activate_at"
      t.timestamps
    end
    
    create_table "delivers", :force => true do |t|
      t.string   "ip", :null => false, :limit => 30
      t.datetime "heartbeat_at"                              
      t.string  "note"
      t.integer  "vpn_port", :default => 1701
      t.integer  "access_points_count", :default => 0      
      t.boolean "available", :defalut => false
      t.boolean "is_running", :defalut => false
      t.integer "city_code"
      t.integer "zone_code"
      t.integer "province_code"
      t.string  "room"
      t.string "server_type"
      t.timestamps
    end
    add_index "delivers", :province_code
    add_index "delivers", :city_code
    add_index "delivers", :zone_code
    
  end
  
  def down
  end
end
